package controller;

import java.util.List;

import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumnModel;

import model.Kunde;

public class CustomerTableModel extends AbstractTableModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5445509955945832777L;
	private TableColumnModel tableColumnModel;
	public final String[] HeaderNames = { "First Name", "Last Name", "Address", "Phone Number"};
	private List<Kunde> customers;

	public CustomerTableModel(List<Kunde> customers) {
		if(customers == null){
			this.customers = PersistenceManager.getInstance().searchKunde("vorname", "");
		}else{
			this.customers = customers;
		}
		System.out.println("Customers i tableModel: " +customers);
	}

	@Override
	public String getColumnName(int column) {
		return HeaderNames[column];
	};

	@Override
	public int getRowCount() {
		return customers.size();
	}

	@Override
	public int getColumnCount() {
		return HeaderNames.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Kunde z = customers.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return z.getVorname();
		case 1:
			return z.getNachname();
		case 2:
			return z.getRechnungsadresse();
		case 3:
			return z.getTelefon();
		}
		return "Error";
	}

	public List<Kunde> getCustomers() {
		return customers;
	}
	
	public void setCustomers(List<Kunde> customers){
		this.customers = customers;
	}
}
